home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_windowmaker.idb / usr / freeware / include / WUtil.h.z / WUtil.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  6.9 KB  |  294 lines

  1. #ifndef _WUTIL_H_
  2. #define _WUTIL_H_
  3.  
  4. #include <X11/Xlib.h>
  5.  
  6. #include <sys/types.h>
  7.  
  8.  
  9. /* SunOS 4.x Blargh.... */
  10. #ifndef NULL
  11. #define NULL ((void*)0)
  12. #endif
  13.  
  14.  
  15. /*
  16.  * Warning: proplist.h #defines BOOL which will clash with the
  17.  * typedef BOOL in Xmd.h
  18.  * proplist.h should use Bool (which is a #define in Xlib.h) instead.
  19.  *
  20.  */
  21. #include <proplist.h>
  22.  
  23.  
  24. #ifndef WMAX
  25. # define WMAX(a,b)    ((a)>(b) ? (a) : (b))
  26. #endif
  27. #ifndef WMIN
  28. # define WMIN(a,b)    ((a)<(b) ? (a) : (b))
  29. #endif
  30.  
  31.  
  32. #if (!defined (__GNUC__) || __GNUC__ < 2 || \
  33.      __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
  34. #define __ASSERT_FUNCTION       ((char *) 0)
  35. #else
  36. #define __ASSERT_FUNCTION       __PRETTY_FUNCTION__
  37. #endif
  38.  
  39.  
  40. #ifdef NDEBUG
  41.  
  42. #define wassertr(expr)        {}
  43. #define wassertrv(expr, val)    {}
  44.  
  45. #else /* !NDEBUG */
  46.  
  47. #define wassertr(expr) \
  48.     if (!(expr)) { \
  49.         wwarning("%s line %i (%s): assertion %s failed",\
  50.             __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
  51.         return;\
  52.     }
  53.  
  54. #define wassertrv(expr, val) \
  55.     if (!(expr)) { \
  56.         wwarning("%s line %i (%s): assertion %s failed",\
  57.             __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
  58.         return (val);\
  59.     }
  60.  
  61. #endif /* !NDEBUG */
  62.  
  63.  
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif /* __cplusplus */
  67.  
  68.  
  69. typedef enum {
  70.     WMPostWhenIdle = 1,
  71.     WMPostASAP = 2,
  72.     WMPostNow = 3
  73. } WMPostingStyle;
  74.  
  75.  
  76. typedef enum {
  77.     WNCNone = 0,
  78.     WNCOnName = 1,
  79.     WNCOnSender = 2
  80. } WMNotificationCoalescing;
  81.  
  82.  
  83.  
  84.  
  85. typedef struct W_HashTable WMHashTable;
  86. typedef struct W_UserDefaults WMUserDefaults;
  87. typedef struct W_Notification WMNotification;
  88. typedef struct W_NotificationQueue WMNotificationQueue;
  89.  
  90.  
  91. /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
  92. typedef struct {
  93.     void *table;
  94.     void *nextItem;
  95.     int index;
  96. } WMHashEnumerator;
  97.  
  98.  
  99. typedef struct {
  100.     /* NULL is pointer hash */
  101.     unsigned     (*hash)(const void *);
  102.     /* NULL is pointer compare */
  103.     Bool    (*keyIsEqual)(const void *, const void *);
  104.     /* NULL does nothing */
  105.     void*    (*retainKey)(const void *);
  106.     /* NULL does nothing */
  107.     void    (*releaseKey)(const void *);    
  108. } WMHashTableCallbacks;
  109.  
  110.  
  111. #if 0
  112. typedef struct {
  113.     char character;               /* the escape character */
  114.     char *value;               /* value to place */
  115. } WMSEscapes;
  116. #endif
  117.  
  118.  
  119. typedef void WMNotificationObserverAction(void *observerData, 
  120.                       WMNotification *notification);
  121.  
  122.  
  123.  
  124. /*......................................................................*/
  125.  
  126. typedef void (waborthandler)(int);
  127.  
  128. waborthandler *wsetabort(waborthandler*);
  129.  
  130.  
  131. void wfatal(const char *msg, ...);
  132. void wwarning(const char *msg, ...);
  133. void wsyserror(const char *msg, ...);
  134.  
  135. char *wfindfile(char *paths, char *file);
  136.  
  137. char *wfindfileinlist(char **path_list, char *file);
  138.  
  139. char *wfindfileinarray(proplist_t array, char *file);
  140.     
  141. char *wexpandpath(char *path);
  142.  
  143. /* don't free the returned string */
  144. char *wgethomedir();
  145.  
  146. void *wmalloc(size_t size);
  147. void *wrealloc(void *ptr, size_t newsize);
  148.  
  149. void wrelease(void *ptr);
  150. void *wretain(void *ptr);
  151.  
  152. char *wstrdup(char *str);
  153.  
  154. char *wstrappend(char *dst, char *src);
  155.  
  156. char *wusergnusteppath();
  157.  
  158. char *wdefaultspathfordomain(char *domain);
  159.  
  160. void wusleep(unsigned int microsec);
  161.  
  162. #if 0
  163. int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
  164.            int count);
  165. #endif
  166. /*......................................................................*/
  167.  
  168.  
  169. WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
  170.  
  171. void WMFreeHashTable(WMHashTable *table);
  172.  
  173. void WMResetHashTable(WMHashTable *table);
  174.  
  175. void *WMHashGet(WMHashTable *table, const void *key);
  176.  
  177. /* put data in table, replacing already existing data and returning
  178.  * the old value */
  179. void *WMHashInsert(WMHashTable *table, void *key, void *data);
  180.  
  181. void WMHashRemove(WMHashTable *table, const void *key);
  182.  
  183. /* warning: do not manipulate the table while using these functions */
  184. WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
  185.  
  186. void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
  187.  
  188. unsigned WMCountHashTable(WMHashTable *table);
  189.  
  190.  
  191.  
  192.  
  193. /* some predefined callback sets */
  194.  
  195. extern const WMHashTableCallbacks WMIntHashCallbacks;
  196. /* sizeof(keys) are <= sizeof(void*) */
  197.  
  198. extern const WMHashTableCallbacks WMStringHashCallbacks;
  199. /* keys are strings. Strings will be copied with wstrdup() 
  200.  * and freed with free() */
  201.  
  202. extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
  203. /* keys are strings, bug they are not copied */
  204.  
  205. /*......................................................................*/
  206.  
  207. WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
  208.  
  209. void WMReleaseNotification(WMNotification *notification);
  210.  
  211. WMNotification *WMRetainNotification(WMNotification *notification);
  212.  
  213. void *WMGetNotificationClientData(WMNotification *notification);
  214.  
  215. void *WMGetNotificationObject(WMNotification *notification);
  216.  
  217. char *WMGetNotificationName(WMNotification *notification);
  218.  
  219.  
  220. void WMAddNotificationObserver(WMNotificationObserverAction *observerAction, 
  221.                    void *observer, char *name, void *object);
  222.  
  223. void WMPostNotification(WMNotification *notification);
  224.  
  225. void WMRemoveNotificationObserver(void *observer);
  226.  
  227. void WMRemoveNotificationObserverWithName(void *observer, char *name, 
  228.                       void *object);
  229.  
  230. void WMPostNotificationName(char *name, void *object, void *clientData);
  231.  
  232. WMNotificationQueue *WMGetDefaultNotificationQueue(void);
  233.  
  234. WMNotificationQueue *WMCreateNotificationQueue(void);
  235.  
  236. void WMDequeueNotificationMatching(WMNotificationQueue *queue, 
  237.                    WMNotification *notification, 
  238.                    unsigned mask);
  239.  
  240. void WMEnqueueNotification(WMNotificationQueue *queue,
  241.                WMNotification *notification,
  242.                WMPostingStyle postingStyle);
  243.  
  244. void WMEnqueueCoalesceNotification(WMNotificationQueue *queue, 
  245.                    WMNotification *notification,
  246.                    WMPostingStyle postingStyle,
  247.                    unsigned coalesceMask);
  248.  
  249.  
  250. /*......................................................................*/
  251.  
  252. WMUserDefaults *WMGetStandardUserDefaults(void);
  253.  
  254. void WMSynchronizeUserDefaults(WMUserDefaults *database);
  255.     
  256. proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
  257.  
  258. void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
  259.              char *defaultName);
  260.  
  261. void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
  262.  
  263. /* you can free the returned string */
  264. char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
  265.  
  266. int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
  267.  
  268. float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
  269.  
  270. Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
  271.  
  272. void WMSetUDStringForKey(WMUserDefaults *database, char *value, 
  273.              char *defaultName);
  274.  
  275. void WMSetUDIntegerForKey(WMUserDefaults *database, int value, 
  276.               char *defaultName);
  277.  
  278. void WMSetUDFloatForKey(WMUserDefaults *database, float value, 
  279.             char *defaultName);
  280.  
  281. void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
  282.                char *defaultName);
  283.  
  284. proplist_t WMGetUDSearchList(WMUserDefaults *database);
  285.  
  286. void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
  287.  
  288. #ifdef __cplusplus
  289. }
  290. #endif /* __cplusplus */
  291.  
  292.  
  293. #endif
  294.